Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid PPEC crash during dithering ops #1263

Merged
merged 14 commits into from
Dec 15, 2024
Merged

Avoid PPEC crash during dithering ops #1263

merged 14 commits into from
Dec 15, 2024

Conversation

bwdev01
Copy link
Contributor

@bwdev01 bwdev01 commented Dec 9, 2024

This is the most restrictive approach because it only applies during dithering. The only identified (rare) field problems occurred during dithering and settling. Generalizing the protection beyond dithering would take more work.

@bwdev01 bwdev01 requested a review from agalasso December 9, 2024 03:35
Comment on lines 746 to 748
catch (std::runtime_error err)
{
throw err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this try..catch -- as far as I can tell it is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't compile without it. The error message is that at least one handler must be specified for the try block in the function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, both the try and catch both should be removed

src/star.cpp Outdated
Comment on lines 1034 to 1036
bool duplicate =
std::find_if(foundStars.begin(), foundStars.end(),
[&tmp](const GuideStar& other) { return CloseToReference(tmp, other); }) != foundStars.end();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change seems to be unrelated to the pr ... let's revert it and get star.cpp out of the pr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same old problem with clang and star.cpp. This has reverted the clang change without me ever opening or touching that file. Something is seriously messed up with this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need to find out what is changing that file in your local environment, and also be sure not to commit the file -- you can run git restore src/star.cpp before you commit it if you notice that it has been changed unintentionally.
Now that the "bad" version has been committed into the branch you can get the old version back with

git restore -s origin/master -- src/star.cpp

(or use any other version you want in place of origin/master)
Then git add git commit and git push to get the branch fixed up on github (origin).

Comment on lines 284 to 285
std::string outStr = "PPEC: Model reset after exception: " + std::string(err.what());
GPDebug->Log(outStr.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log takes a printf-style format string so this could be a little dangerous (I'm thinking of the case where outStr contains a % character somewhere)
Here's is a safer way that also gets rid of the unneeded temporary string construction:

Suggested change
std::string outStr = "PPEC: Model reset after exception: " + std::string(err.what());
GPDebug->Log(outStr.c_str());
GPDebug->Log("PPEC: Model reset after exception: %s", err.what());

{
deduceResult(time_step); // just pretend we would do dark guiding...
}
catch (std::runtime_error err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: can think of the catch args as like method arguments, and it is a good practice to pass objects by const reference where we want reference semantics (pass by reference) and do not need copy semantics (pass by value):

Suggested change
catch (std::runtime_error err)
catch (const std::runtime_error& err)

@bwdev01
Copy link
Contributor Author

bwdev01 commented Dec 9, 2024 via email

@agalasso
Copy link
Contributor

agalasso commented Dec 9, 2024

Are you proposing that the throw shouldn’t be enclosed in a try/catch block?

correct. The exception thrown in GaussianProcessGuider::regularize_dataset will be caught and handled by the catch block in GaussianProcessGuider::result. The intermediate catch block in GaussianProcessGuider::regularize_dataset that is catching the original exception, copying it, then throwing the copy is unnecessary.

The PHD2 code base until this PR does not let exceptions propagate outside functions but with this PR we are introducing propagation outside functions here as an exception to the rule; we may come back to this and update the code to be able to return the error condition without resorting to raising the exception, or better, fix the code to handle the exceptional case locally if possible. I think the raising of the exception is a reasonable solution in this specific case for now.

@bwdev01
Copy link
Contributor Author

bwdev01 commented Dec 12, 2024 via email

@agalasso
Copy link
Contributor

Regarding the log output for the throw message. Doing it the way you suggested results in this

@bwdev01 GPDebug::Log is not working correctly for %s arguments -- a latent bug this PR is now triggering it as it is the first use of %s in GPDebug. I'm looking into it now...

@agalasso
Copy link
Contributor

@bwdev01 if #1264 looks ok to you, we can merge that to master so you can make use of it in this pr, something like this:

    std::ostringstream message;
    message << "PPEC: Model reset after exception: " << err.what();
    GPDebug->Write(message.str().c_str());

@bwdev01 bwdev01 requested a review from agalasso December 15, 2024 18:11
Copy link
Contributor

@agalasso agalasso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, one minor suggestion

@bwdev01 bwdev01 requested a review from agalasso December 15, 2024 20:29
Copy link
Contributor

@agalasso agalasso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work

@bwdev01 bwdev01 merged commit f8ecbfb into master Dec 15, 2024
2 checks passed
@bwdev01 bwdev01 deleted the PPEC_Crash_Fix3 branch December 15, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants